import { Http } from "../utils/http";

class User extends Http {
  constructor(props) {
    super(props);
  }

  // 微信用户信息解密;
  userDecrypt(code) {
    return this.request({
      url: "/mini/user/userDecrypt",
      data: {
        code,
      },
      method: "POST",
    });
  }

  // 微信登录
  userWxLogin(params) {
    return this.request({
      url: "/mini/user/wxLogin",
      data: params,
      method: "POST",
    });
  }

  //账号密码登录
  pwLogin(userName, password) {
    return this.request({
      url: "/app/user/login",
      data: {
        phone: userName,
        password,
      },
      method: "POST",
    });
  }

  //微信登录--以前的微信登录接口   先不要删除
  // wxLogin(code) {
  //   return this.request({
  //     url: "",
  //     data: {
  //       code,
  //     },
  //     method: "POST",
  //   });
  // }
  //注册获取验证码
  registerGetAuthCode(phone, type = 1) {
    return this.request({
      // url: "/mini/user/appCheckLogin",
      url: "/mini/user/sendCheckCode",
      data: {
        phone,
        type,
      },
      method: "POST",
    });
  }
  //设置密码
  setUserPassword(phone, password) {
    return this.request({
      url: "/mini/user/appRegisterSetPassWord",
      data: {
        phone,
        password,
      },
      method: "POST",
    });
  }
  //验证码修改密码
  forgetPassword(phone, password) {
    return this.request({
      url: "/app/user/forgetPassword",
      data: {
        phone,
        password,
      },
      method: "POST",
    });
  }

  userLogin(phone, password) {
    return this.request({
      url: "/mini/user/appLogin",
      data: {
        phone,
        password,
      },
      method: "POST",
    });
  }

  wxLogin(code) {
    return this.request({
      url: "/mini/user/wxLogin",
      method: "post",
      data: {
        code,
      },
    });
  }

  wxBinding(code, phone, url, username, password) {
    return this.request({
      url: "/mini/user/wxBinding",
      method: "post",
      data: {
        code,
        phone,
        url,
        username,
        password,
      },
    });
  }

  getUserCommunity() {
    return this.request({
      url: "/mini/house/list",
      method: "get",
    });
  }
  // 获取用户单元号
  getCommgates(commid) {
    return this.request({
      url: "/mini/house/commgates",
      method: "get",
      data: {
        commid,
      },
    });
  }

  //检验验证码
  appCheckCode(phone, checkCode) {
    return this.request({
      url: "/mini/user/appCheck",
      method: "post",
      data: {
        phone,
        checkCode,
      },
    });
  }

  appCheckLogin(phone, checkCode) {
    return this.request({
      url: "/mini/user/appCheckLogin",
      method: "post",
      data: {
        phone,
        checkCode,
      },
    });
  }

  //修改昵称
  editNickname(username) {
    return this.request({
      url: "/mini/user/updateUsername",
      method: "post",
      data: {
        username,
      },
    });
  }

  logout() {
    return this.request({
      url: "/mini/user/logout",
      method: "get",
    });
  }

  //修改密码
  edidPassword(password, newPassword) {
    return this.request({
      url: "/mini/user/updatePassword",
      method: "post",
      data: {
        password,
        newPassword,
      },
    });
  }

  //获取用户房屋信息和房屋列表
  getUserInfo() {
    return this.request({
      url: "/mini/user/getUserInfo",
      method: "get",
    });
  }

  //修改手机号
  editPhone(phone) {
    return this.request({
      url: "/mini/user/updatePhone",
      method: "post",
      data: {
        phone,
      },
    });
  }

  //首页小区    个人中心上方显示信息
  centerCellSelection() {
    return this.request({
      url: "/mini/center/cellSelection",
      method: "get",
    });
  }

  // 扫码开门---------------------------------------------------------------------
  miniVisitorOpenTheDoor(params) {
    return this.request({
      url: "/mini/miniVisitor/openTheDoor",
      method: "get",
      data: params,
    });
  }

  // 个人中心---------------------------------------------------------------------
  //个人中心--居住信息列表
  residentialAddress(pageNo = 1, pageSize = 10) {
    return this.request({
      url: "/mini/center/residential/address",
      method: "get",
      data: {
        pageNo,
        pageSize,
      },
    });
  }

  //个人中心--居住信息--添加住址
  houseAddress(data) {
    return this.request({
      url: "/mini/center/add/house/address",
      method: "post",
      data: data,
    });
  }

  //个人中心--居住信息--删除
  deleteHouseHold(houseMemberId) {
    return this.request({
      url: `/mini/center/delete/house/hold/?houseMemberId=${houseMemberId}`,
      method: "delete",
    });
  }

  // 个人中心--居住信息--详情--我添加的--删除
  deleteHouseLive(houseMemberId) {
    return this.request({
      url: `/mini/center/delete/house/live/?houseMemberId=${houseMemberId}`,
      method: "delete",
    });
  }

  //个人中心--居住信息--设为当前默认居住地址
  residentialAddressDefault(data) {
    return this.request({
      url: "/mini/center/residential/address",
      method: "put",
      data: data,
    });
  }

  //个人中心--居住信息--详情列表
  addressDetails(houseId, pageNum = 1, pageSize = 10) {
    return this.request({
      url: "/mini/center/address/details",
      method: "get",
      data: {
        houseId: houseId,
        pageNum,
        pageSize,
      },
    });
  }

  //个人中心--居住信息--详情列表--添加住户
  addHouseHold(data) {
    return this.request({
      url: "/mini/center/add/house/hold",
      method: "post",
      data: data,
    });
  }

  //个人中心--居住信息--详情--我添加的--详情
  houseHoldDetail(data) {
    return this.request({
      url: "/mini/center/house/hold/detail",
      method: "get",
      data: data,
    });
  }

  //个人中心--基本信息
  basicInformation(params) {
    return this.request({
      url: "/mini/center/basic/information",
      method: "get",
      data: params,
    });
  }

  //个人中心--基本信息--保存
  basicInformationSub(data) {
    return this.request({
      url: "/mini/center/basic/information",
      method: "put",
      data: data,
    });
  }
}

export default User;
